package com.magic.zhixin.controller;

import com.magic.zhixin.entity.Result;
import com.magic.zhixin.entity.UserInfo;
import com.magic.zhixin.entity.UserTopic;
import com.magic.zhixin.entity.UserTopicDetail;
import com.magic.zhixin.service.ZhiXinLiuYanService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api/zhixinliuyan/")
public class ZhiXinLiuYanController extends BaseController {

    @Autowired
    private ZhiXinLiuYanService zhiXinLiuYanService;

    @GetMapping("addUserTopic")
    @ApiOperation(value = "发布话题")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "title", value = "", required = true, dataType = "String"),
    })
    public Result<UserTopic> addUserTopic(@RequestParam(name = "title") String title) {
        UserInfo userInfo = currentUser();
        return zhiXinLiuYanService.addUserTopic(title, userInfo);
    }

    @GetMapping("getUserTopic")
    @ApiOperation(value = "获取自己的话题")
    @ApiImplicitParams({
    })
    public Result<UserTopic> getUserTopic() {
        UserInfo userInfo = currentUser();
        return zhiXinLiuYanService.getUserTopic(userInfo);
    }

    @GetMapping("getHotUserTopic")
    @ApiOperation(value = "获取热门话题")
    @ApiImplicitParams({
    })
    public Result<UserTopic> getHotUserTopic() {
        return zhiXinLiuYanService.getHotUserTopic();
    }

    @GetMapping("getAllUserTopicDetail")
    @ApiOperation(value = "获取话题所有留言")
    @ApiImplicitParams({
    })
    public Result<UserTopicDetail> getAllUserTopicDetail(Long userTopicId) {
        return zhiXinLiuYanService.getAllUserTopicDetail(userTopicId);
    }

    @GetMapping("addComment")
    @ApiOperation(value = "添加留言")
    @ApiImplicitParams({
    })
    public Result<UserTopicDetail> addComment(String content,Long userTopicId) {
        UserInfo userInfo = currentUser();
        return zhiXinLiuYanService.addComment(content,userInfo,userTopicId);
    }



}